﻿using SCG.General;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TTEngine
{
    public class OilPool : MapObject
    {
        //constructor
        public OilPool()
            : base()
        {
            Flamability = 33;
            _spread = Globals.RandomIntFromTo(4, 10);
            CanCollapse = false;
            BurnLifetime = Globals.RandomIntFromTo(20, 30);
        }
        public OilPool(int spread)
            : base()
        {
            Flamability = 33;
            _spread = 0;
            CanCollapse = false;
            BurnLifetime = Globals.RandomIntFromTo(20, 30);
        }

        //object name
        public override string ObjectName
        {
            get
            {
                return "Oil Pool";
            }
        }

        //clone
        public override MapObject Clone()
        {
            return new OilPool();
        }

        //spread
        public override void ProcessImpulse()
        {
            base.ProcessImpulse();
            if (_spread > 0)
            {
                _spread--;
                SCGPoint pt = Level.GetSpreadPoint(X, Y, "Oil Pool", false);
                if (pt != null)
                {
                    OilPool newPool = new OilPool(0);
                    Level.AddObjectToMap(newPool, pt.X, pt.Y);
                }
            }

            //make actors in the oil pool slip
            Actor actor = Level.GetActorAt(X, Y, false);
            if (actor != null)
            {
                if (actor.HasTag("Cannot Fall"))
                    return;
                if (actor.PerformTest(Abilities.Dexterity, 2, 0))
                    return;
                actor.AddCondition("Prone");
            }
        }

        //keep it around while burning
        public override void Burn()
        {
            if (_isBurning)
                return;
            Flamability = 0;
            _isBurning = true;
            Fire fire = new Fire();
            fire.Lifetime = Globals.RandomIntFromTo(20, 30);
            Lifetime = fire.Lifetime;
            Level.AddObjectToMap(fire, X, Y);
        }

        //private members
        private int _spread;
        private bool _isBurning;
    }
}
